#!/usr/bin/perl

($VARIANT, $TEMPLATE_FILE, $OUTFILE) = @ARGV;

$TIME = '';
if ($#ARGV == 3){
  $TIME = $ARGV[3];
}

open(DAT, $TEMPLATE_FILE);
{
local($/);
$content = <DAT>;
}
close(DAT);

$dir = lc($VARIANT);

$content =~ s/<!--#TEMPLATE:IF (?:[\w ,]+,)?$VARIANT(?:,[\w ,]+)?-->(.*?)<!--#TEMPLATE:END IF-->/\1/gs;
$content =~ s/<!--#TEMPLATE:IF .*?-->.*?<!--#TEMPLATE:END IF-->//gs;
$content =~ s/<!--#TEMPLATE:PATH-->/$dir/gs;
$content =~ s/<!--#TEMPLATE:TIME-->/$TIME/gs;

open(DAT, ">$OUTFILE");
print DAT $content;
close(DAT);



